#ifndef	__CXX_VIEWS_GRPH_PEN_IMPL_H__
#define	__CXX_VIEWS_GRPH_PEN_IMPL_H__

#include "canvas.h"
#include "grphoal.h"

namespace visgrph
{

using namespace grphoal;
extern syncobject g_pen_syncobj;

class pen_impl
{
public:
	pen_impl() : m_width(1), m_flags(pen_flag_solid_style)
	{
	}

	pen_impl(const pen_impl& p) {
		assign(p);
	}

	pen_impl(float width, color c, pen_style ps = pen_style_solid)
		: m_width(width), m_color(c), m_flags(0)
	{
		if (m_width < 0) m_width = 0;
		if (ps == pen_style_dotline)
		{
			m_flags |= pen_dotline_pattern_default;
			m_flags |= pen_flag_dotline_style;
		}
		else m_flags |= pen_flag_solid_style;
	}

	~pen_impl() {}

	pen_impl& assign(const pen_impl& p)
	{
		if (this != &p)
		{
			autosync sync(g_pen_syncobj);
			m_width = p.m_width;
			m_color = p.m_color;
			m_flags = p.m_flags;
		}
		return *this;
	}

	pen_impl& operator=(pen_impl& p) {
		return assign(p);
	}

	void set_width(float width) {
		m_width = width;
	}

	void set_color(color c) {
		m_color = c;
	}

	bool set_dotmask(uint mask)
	{
		autosync sync(g_pen_syncobj);
		if (m_flags & pen_flag_dotline_style)
		{
			m_flags &= ~0xFFFF;
			m_flags |= (mask & 0xFFFF);
			return true;
		}
		else return false;
	}

	pen_cap_type cap_type(pen_cap_type type = pen_cap_type_unknown)
	{
		if (pen_cap_type_unknown != type)
		{
			if (pen_cap_type_round == type)
				m_flags |= pen_flag_round_cap;
			else
				m_flags &= ~pen_flag_round_cap;
			return type;
		}
		return (m_flags & pen_flag_round_cap)
			? pen_cap_type_round : pen_cap_type_flat;
	}

	pen_join_type join_type(pen_join_type type = pen_join_type_unknown)
	{
		if (pen_join_type_unknown != type)
			m_jointype = type;
		return m_jointype;
	}

	float width(void) { return m_width; }
	color _color(void) { return m_color; }

private:
	enum pen_flags
	{
		pen_flag_solid_style = (1 << 16),
		pen_flag_dotline_style = (1 << 17),
		pen_flag_round_cap = (1 << 18),
	};

	enum pen_dotline_pattern
	{
		pen_dotline_pattern_default = 0x3333,
	};
	color	m_color;
	float	m_width;
	uint	m_flags;
	pen_join_type m_jointype;
};

};	// namespace visgrph

#endif	// __CXX_VIEWS_GRPH_PEN_IMPL_H__
/* EOF */

